//
//  LSZAppraiseTableViewCell.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/12/22.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZAppraiseTableViewCell.h"

@implementation LSZAppraiseTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageViewHeader = [[UIImageView alloc]init];
        [self.imageViewHeader.layer setMasksToBounds:YES];
        self.imageViewHeader.userInteractionEnabled = YES;
        [self addSubview:self.imageViewHeader];

        self.labelName = [[UILabel alloc]init];
        self.labelName.textColor = RGBColor(63, 91, 173);
        self.labelName.userInteractionEnabled = YES;
        [self addSubview:self.labelName];

        self.butZan = [[UIButton alloc]init];
        self.butZan.userInteractionEnabled = YES;
        [self addSubview:self.butZan];

        self.imageViewShou = [[UIImageView alloc]init];
        self.imageViewShou.image = [UIImage imageNamed:@"我的_签到_留言_点赞"];
        self.imageViewShou.userInteractionEnabled = YES;
        [self.butZan addSubview:self.imageViewShou];

        self.labelZanNumber = [[UILabel alloc]init];
        self.labelZanNumber.textColor = lightColor;
        self.labelZanNumber.userInteractionEnabled = YES;
        [self.butZan addSubview:self.labelZanNumber];

        self.labelTime = [[UILabel alloc]init];
        self.labelTime.userInteractionEnabled = YES;
        self.labelTime.textColor = lightColor;
        [self addSubview:self.labelTime];

        self.labelContent =  [[UILabel alloc]init];
        self.labelContent.numberOfLines = 0;
        self.labelContent.textColor =  titleColorLSZ;
        self.labelContent.userInteractionEnabled = YES;
        [self addSubview:self.labelContent];

        self.labelNumberEvaluation = [[UILabel alloc]init];
        self.labelNumberEvaluation.backgroundColor = RGBColor(246, 246, 246);
        self.labelNumberEvaluation.textColor = RGBColor(73, 88, 136);
        self.labelNumberEvaluation.hidden = YES;
        [self.labelNumberEvaluation.layer setMasksToBounds:YES];
        [self.labelNumberEvaluation.layer setCornerRadius:12.5];
        [self.labelNumberEvaluation.layer setBorderWidth:1];
        [self.labelNumberEvaluation.layer setBorderColor:RGBColor(236, 236, 236).CGColor];
        self.labelNumberEvaluation.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.labelNumberEvaluation];

        if (ScreenWidth == 320) {
            //5
            self.labelName.font = FONT_(14.5);
            self.labelTime.font = FONT_(13.5);
            self.labelZanNumber.font = FONT_(13.5);
            self.labelContent.font = FONT_(13.5);
            self.labelNumberEvaluation.font = FONT_(13.5);

            self.imageViewHeader.frame = CGRectMake(15, 9, 37, 37);
            [self.imageViewHeader.layer setCornerRadius:18.5];
            self.labelName.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, 9 , 150, 18);
            self.labelTime.frame = CGRectMake(CGRectGetMinX(self.labelName.frame), CGRectGetMaxY(self.labelName.frame)+3,self.labelName.frame.size.width, 16);
            self.butZan.frame = CGRectMake(ScreenWidth-100,self.imageViewHeader.frame.origin.y,100, self.imageViewHeader.frame.size.height);
            self.imageViewShou.frame = CGRectMake(14+25,(self.butZan.frame.size.height-16)/2, 16, 16);
            self.labelZanNumber.frame = CGRectMake(CGRectGetMaxX(self.imageViewShou.frame)+2, (self.butZan.frame.size.height-16)/2, self.butZan.frame.size.width-CGRectGetMaxX(self.imageViewShou.frame)-2, 16);
            self.labelContent.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, CGRectGetMaxY(self.labelTime.frame)+5, ScreenWidth-CGRectGetMaxX(self.imageViewHeader.frame)-5-15, 35);
            self.labelNumberEvaluation.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, CGRectGetMaxY(self.labelContent.frame)+7,100,25);

        }else if(ScreenWidth == 375){
            // 6 7
            self.labelName.font = FONT_(15);
            self.labelTime.font = FONT_(14);
            self.labelZanNumber.font = FONT_(14);
            self.labelContent.font = FONT_(14);
            self.labelNumberEvaluation.font = FONT_(14);

            self.imageViewHeader.frame = CGRectMake(15, 9, 41, 41);
            [self.imageViewHeader.layer setCornerRadius:20.5];
            self.labelName.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, 9 , 150, 20);
            self.labelTime.frame = CGRectMake(CGRectGetMinX(self.labelName.frame), CGRectGetMaxY(self.labelName.frame)+3,self.labelName.frame.size.width, 18);
            self.butZan.frame = CGRectMake(ScreenWidth-100,self.imageViewHeader.frame.origin.y,100, self.imageViewHeader.frame.size.height);
            self.imageViewShou.frame = CGRectMake(12+25,(self.butZan.frame.size.height-18)/2, 18, 18);

            self.labelZanNumber.frame = CGRectMake(CGRectGetMaxX(self.imageViewShou.frame)+2, (self.butZan.frame.size.height-18)/2, self.butZan.frame.size.width-CGRectGetMaxX(self.imageViewShou.frame)-2, 18);
            self.labelContent.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, CGRectGetMaxY(self.labelTime.frame)+5, ScreenWidth-CGRectGetMaxX(self.imageViewHeader.frame)-5-15, 35);
            self.labelNumberEvaluation.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, CGRectGetMaxY(self.labelContent.frame)+7,100,27.5);

        }else {
            //plus
            self.labelName.font = FONT_(15.5);
            self.labelTime.font = FONT_(14.5);
            self.labelZanNumber.font = FONT_(14.5);
            self.labelContent.font = FONT_(14.5);
            self.labelNumberEvaluation.font = FONT_(14.5);

            self.imageViewHeader.frame = CGRectMake(15, 9, 45, 45);
            [self.imageViewHeader.layer setCornerRadius:22.5];
            self.labelName.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, 9 , 150, 22);
            self.labelTime.frame = CGRectMake(CGRectGetMinX(self.labelName.frame), CGRectGetMaxY(self.labelName.frame)+3,self.labelName.frame.size.width, 20);
                self.butZan.frame = CGRectMake(ScreenWidth-100,self.imageViewHeader.frame.origin.y,100, self.imageViewHeader.frame.size.height);
            self.imageViewShou.frame = CGRectMake(10+25,(self.butZan.frame.size.height-20)/2, 20, 20);

            self.labelZanNumber.frame = CGRectMake(CGRectGetMaxX(self.imageViewShou.frame)+2, (self.butZan.frame.size.height-20)/2, self.butZan.frame.size.width-CGRectGetMaxX(self.imageViewShou.frame)-2, 20);
            self.labelContent.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, CGRectGetMaxY(self.labelTime.frame)+5, ScreenWidth-CGRectGetMaxX(self.imageViewHeader.frame)-5-15, 35);
            self.labelNumberEvaluation.frame = CGRectMake(CGRectGetMaxX(self.imageViewHeader.frame)+5, CGRectGetMaxY(self.labelContent.frame)+7,100,30);
        }
        self.viewLow = [[UIView alloc]initWithFrame:CGRectMake(20, 0, ScreenWidth-40, 0.3)];
        self.viewLow.backgroundColor = divider;
        [self addSubview:self.viewLow];
    }
    return self;
}
-(void)setResourceEvaluationListMg:(LSZResourceEvaluationListMg *)ResourceEvaluationListMg
{
    NSString * str = [NSString stringWithFormat:@"%@",ResourceEvaluationListMg.publisherHead];
    [self.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    if ([NSStr(ResourceEvaluationListMg.publisher) isEqualToString:@""]) {
        self.labelName.text = [NSString stringWithFormat:@"SJ_%@",ResourceEvaluationListMg.publisherId];
    }else{
        self.labelName.text = [NSString stringWithFormat:@"%@",ResourceEvaluationListMg.publisher];
    }
    self.labelZanNumber.text = [NSString stringWithFormat:@"%@",ResourceEvaluationListMg.praiseNum];
    self.labelTime.text =  [NSString stringWithFormat:@"%@",ResourceEvaluationListMg.publishTime];
    CGFloat intFont = [LSZSpecialPackaging initWithReturnsthesizeOf:14 :0.5];

    CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:intFont :ResourceEvaluationListMg.content];
    self.labelContent.text = ResourceEvaluationListMg.content;

    CGRect rect = self.labelContent.frame;
    rect.size.height = height;
    self.labelContent.frame = rect;

    if([NSStr(ResourceEvaluationListMg.commentNum) isEqualToString:@"0"]||NSStr(ResourceEvaluationListMg.commentNum).length == 0||[NSStr(ResourceEvaluationListMg.commentNum) isEqualToString:@""]){
        self.labelNumberEvaluation.hidden = YES;
    }else{
        self.labelNumberEvaluation.hidden = NO;
        self.labelNumberEvaluation.text = [NSString stringWithFormat:@"查看%@条回复", NSStr(ResourceEvaluationListMg.commentNum)];
        CGRect rect = self.labelNumberEvaluation.frame;
        rect.origin.y = CGRectGetMaxY(self.labelContent.frame);
        self.labelNumberEvaluation.frame = rect;
    }
}
#pragma mark - 动态的赋值
-(void)setDynamicCommentDetailsMg:(LSZDynamicCommentDetailsMg *)dynamicCommentDetailsMg
{
    NSString * str = [NSString stringWithFormat:@"%@",dynamicCommentDetailsMg.avatar];
    [self.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"placeholder"]];

    if([dynamicCommentDetailsMg.is_admire isEqualToString:@"0"]){
        self.imageViewShou.image = [UIImage imageNamed:@"点赞"];
    }else{
        self.imageViewShou.image = [UIImage imageNamed:@"我的_签到_留言_已点赞"];
    }

    if ([NSStr(dynamicCommentDetailsMg.username) isEqualToString:@""]) {
        self.labelName.text = [NSString stringWithFormat:@"SJ_%@",dynamicCommentDetailsMg.uid];
    }else{
        self.labelName.text = [NSString stringWithFormat:@"%@",dynamicCommentDetailsMg.username];
    }
    self.labelZanNumber.text = [NSString stringWithFormat:@"%@",dynamicCommentDetailsMg.admire_num];
    self.labelTime.text =  [NSString stringWithFormat:@"%@",dynamicCommentDetailsMg.add_time];
    CGFloat intFont = [LSZSpecialPackaging initWithReturnsthesizeOf:14 :0.5];
    CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:intFont :dynamicCommentDetailsMg.content];
    self.labelContent.text = dynamicCommentDetailsMg.content;

    CGRect rect = self.labelContent.frame;
    rect.size.height = height;
    self.labelContent.frame = rect;

    if([NSStr(dynamicCommentDetailsMg.comment_num) isEqualToString:@"0"]||NSStr(dynamicCommentDetailsMg.comment_num).length == 0||[NSStr(dynamicCommentDetailsMg.comment_num) isEqualToString:@""]){
        self.labelNumberEvaluation.hidden = YES;
    }else{
        self.labelNumberEvaluation.hidden = NO;
        self.labelNumberEvaluation.text = [NSString stringWithFormat:@"查看%@条回复", NSStr(dynamicCommentDetailsMg.comment_num)];
        CGRect rect = self.labelNumberEvaluation.frame;
        rect.origin.y = CGRectGetMaxY(self.labelContent.frame);
        self.labelNumberEvaluation.frame = rect;
    }
}
@end
